package gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import application.ArenaManager;

public class LoginFrame extends JPanel {

	private JTextField textField;
	private JPasswordField passwordField;
	private JLabel lblNoUser;

	public LoginFrame() {
		setVisible(true);
		setBounds(100, 100, 450, 300);
		setBorder(new EmptyBorder(5, 5, 5, 5));
		setLayout(new BorderLayout(0, 0));
		
		JPanel panel = new JPanel();
		add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JLabel lblPassword = new JLabel("Password");
		lblPassword.setBounds(12, 157, 63, 24);
		panel.add(lblPassword);
		
		JLabel lblEmail = new JLabel("Email");
		lblEmail.setBounds(12, 128, 63, 31);
		panel.add(lblEmail);
		
		textField = new JTextField();
		textField.setBounds(87, 131, 167, 24);
		panel.add(textField);
		textField.setColumns(10);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(87, 158, 167, 24);
		panel.add(passwordField);
		
		JLabel lblEnterYourEmail = new JLabel("Enter your email and password");
		lblEnterYourEmail.setBounds(12, 95, 242, 24);
		panel.add(lblEnterYourEmail);
		
		JButton btnLogin = new JButton("Login");
		btnLogin.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				authenticate();					
			}
		});
		btnLogin.setBounds(12, 194, 89, 23);
		panel.add(btnLogin);
		
		lblNoUser = new JLabel("");
		lblNoUser.setForeground(UIManager.getColor("ToolBar.dockingForeground"));
		lblNoUser.setBounds(266, 137, 162, 44);
		panel.add(lblNoUser);
	}
	
	private void authenticate() {
		ArenaManager.getInstance().login(textField.getText(), passwordField.getText());		
	}

}
